A Very Atari Christmas

Author: @OxC0FFEE (Kim Slawson)
System: ATARI 8-bit
Language: BASIC (TurboBasic XL) 
Source code length: 1 line, 205 bytes (including EOF)
Executable code length: same as above (BASIC is interpreted)

Instructions: 
You can mount the included .atr file in an emulator (I used Atari800MacX),
or write it to a disk and run it on a real Atari, or mount the disk imager
with a FujiNet! If you're really feeling old-school, you can type in the
basic listing yourself (just make sure you're using TurboBasic XL).

Comments: 
I enjoyed doing this exercise and crunching it down as small as I could.
Wait until after the tree draws for a surprise :-)

Description of code:

rem  Stuff ATASCII character code values into a string for compact storage
rem  (these correspond to the number of asterisks per line,
rem   for example: 1,3,5,7...)
rem  ADR gets the address in memory of said string. We'll need this later.
D=adr("\01\03\05\07\03\07\0B\0F\05\0B\11\17\03\03")

rem  Use mode 7 without the text window (7+16)
gr.23

rem  Make the trunk color brown
poke 708,38

rem  Make the rest of the tree green (note the dual poke into the third
rem  color register (same as poke 709,198:poke 710,198 but it saves space).
rem  Why three colors instead of just two? You'll see ;-)
dpoke 709,50886

rem  nested loops to plot the tree: 
rem  - y is vert coord, 
rem  - i is horiz index for each line, 
rem  - w is width of each line,
rem  - z is overall counter incremented for each asterisk
for y=0 to 13

rem  We need to find the width of the current line:
rem  Get the yth character in the string array we previously defined.
rem  Why do it this way? Because it's more compact than using DATA/READ.
  w=peek(d+y)
  for i=1 to w

rem  this is a compact expression to pick the color of the line to plot.
rem  - color 1 is tree trunk color, used when the conditionals returns 0.
rem  - colors 2 and 3 are the needles, green. Why 2 greens? 🤔 you'll see!
rem  - (y<12) returns true for lines 0-11 (green) & false for 12&13 (brown) 
rem  - (frac(z/w)=0)+1 returns 2 (the first green color) unless z is
rem    divisible by w, in which case it returns 3 (the second green color),
       giving a pleasing distribution of color 3 amongst mostly color 2.
    color 1+(y<12)*((frac(z/w)=0)+1)

rem  this plots an asterisk in its proper place:
rem  - 74 is roughly the middle of the screen
rem  - make each character 7px wide instead of 8 because we need to squish
rem    it horizonally a little to fit it on the screen.
rem    (the widest line is 23 * across, but the Atari only has 20 across
rem    in mode 2 characters, which is essentially what we're building,
rem    using TEXT in mode 7)
rem  - divide by 2 to center on the screen
rem  - make each character 6px tall instead of 8, again because we need to
rem    squish the tree a bit vertically to fit it all onscreen
rem    (the tree is 14 lines tall, but the screen only fits 12 8x8 chars)
	text 74-w*7/2+i*7,y*6,"*"

rem  increment the counter so we can pick which green to use in the color
rem  statement above.
	z=z+1
  next i
next y

rem  here's a loop so the tree stays on the screen at the end instead of
rem  returning to the READY prompt in textmode 0
do

rem  pause a little, because...
pause 10

rem  SURPRISE! The second green color is for flashing the "lights" we
rem  intermittently plotted at divisible intervals of z:
rem  Flash brighter green randomly, 1 out of 11 times, by changing color 3
rem  to an intensity 4 steps brighter.
  poke 710,198+4*INT(RAND(11)/10)
loop

rem  HAPPY 8-BIT CHRISTMAS! The end!
rem             🌟
rem            ***
rem           *****
rem          *******
rem            ***
rem          *******
rem        ***********
rem      ***************
rem           *****
rem        ***********
rem     *****************
rem  *********************** 
rem            ***
rem            ***
